import { Router } from 'vue-router';
import { useUserStoreWithOut } from '/@/store/user';
import { PageEnum } from '/@/enums/pageEnum';

export function createPermissionGuard(router: Router) {
  const userStore = useUserStoreWithOut();
  router.beforeEach(async (to, from, next) => {

    console.log(to)

    if (to.meta && to.meta.name) {
      document.title = to.meta.name as string
    } else {
      document.title = '注册下载运天下'
    }

    // const token = userStore.getToken;
    // if (to.path == PageEnum.BASE_HOME) {
    //   next();
    //   return;
    // }

    // if (!token) {
    //   const redirectData: { path: string; replace: boolean; query?: Recordable<string> } = {
    //     path: PageEnum.BASE_HOME,
    //     replace: true
    //   };
    //   next(redirectData);
    //   return;
    // }
    next();
    return;
  });
}
